package com.speily.bigdata.kafka.controller;

import com.speily.bigdata.kafka.KafkaSendMsgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: SPL
 * @Date: 2019-07-22 13:31
 * @Description: -
 */
@RestController
public class providerController {


    @Autowired
    private KafkaTemplate<Integer, String> kafkaTemplate;   //注入kafka

    @RequestMapping("/test")
    public Object test(){
        // 1
        ListenableFuture<SendResult<Integer, String>> res = kafkaTemplate.send("topic","消息已发送！");

        // 2
        KafkaSendMsgUtils.sendMessage("topic1",0,null,"key","kafka-test");
        return res;
    }




}
